<?
$documentCode = extractNumberWithKeyFromArray('documentCode', $_REQUEST, null);
$pageNumber = extractNumberWithKeyFromArray('pageNumber', $_REQUEST, null);


$row = $cmsDocument->openDocument($documentCode);
$status = $cmsDocument->openDocument($row->extra4);

$cmsDocument->flush();
$cmsDocument->addDocumentType("docOdrItm");
$cmsDocument->addConstraint("author", $row->categorycode);
$cmsDocument->addSort("title");
$cmsDocument->resetIterator();

$orderItems = array();
while($row2 = $cmsDocument->nextDocument()){
//	/$orderItems[] = $row2;
	array_push($orderItems, $row2);
}


//check here for a custom order view page.. unlike the browse mechanism, we dont need to 
// actually have an array.. just a define for one page..


if (defined("CMS_CUSTOM_ORDER_VIEW")) {
	include(CMS_CUSTOM_ORDER_VIEW);
} else {

?>
<style type="text/css">
<!--
.style7 {color: #333333; font-weight: bold; }
.style8 {color: #666666; }
-->
</style>
	<div class="formStyle">
			<label>Order Id:</label>
			<div class="detail">
				<?=$row->categorycode?>
			</div>
	</div>
	
    <div class="formStyle">
			<label>Date Added:</label>
			<div class="detail">
			<?=$row->datelogged?>
			</div>
	</div>
	
	<div class="formStyle">
			<label>First Name:</label>
			<div class="detail">
				<?=magicclean($row->authordepartment,false)?>
			</div>
	</div>
	
    <div class="formStyle">
			<label>Last Name:</label>
			<div class="detail">
				<?=magicclean($row->organisationalname,false)?>
			</div>
	</div>
	
	<div class="formStyle">
			<label>Email:</label>
			<div class="detail">
				<?=magicclean($row->authorbio,false)?>
			</div>
	</div>
	
    <div class="formStyle">
			<label>Status:</label>
			<div class="detail">
				<?=$status->title?>
			</div>
	</div>
	
	<div class="formStyle">
			<label>Phone:</label>
			<div class="detail">
				<?=magicclean($row->value,false)?>
			</div>
	</div>
	
    <?php /* ?><div class="formStyle">
			<label>Phone Night:</label>
			<div class="detail">
				<?=magicclean($row->inhouse,false)?>
			</div>
	</div>
	
	<div class="formStyle">
			<label>Mobile:</label>
			<div class="detail">
				<?=magicclean($row->restricted,false)?>
			</div>
	</div><?php */ ?>
	
	<div class="clear"></div>
    
  <?if($row->address){?>
  <div id="cms_masteredit_174_12037" class="formStyle">
    <label>Delivery Address</label>
  </div>  
  <div id="cms_masteredit_174_12037" class="formStyle">
    <label>Street:</label>
    <div class="detail">
		<?=magicclean($row->address,false)?>
	</div>
   </div> 
  <div id="cms_masteredit_174_12037" class="formStyle">
	<label>Suburb:</label>
    <div class="detail">
		<?=magicclean($row->phone,false)?>
	</div>
  </div>
  <div id="cms_masteredit_174_12038" class="formStyle">
    <label>City:</label>
    <div class="detail">
		<?=magicclean($row->fax,false)?>
	</div>
  </div>
	<div id="cms_masteredit_174_12038" class="formStyle">
    <label>Country:</label>
    <div class="detail">
		<?=magicclean($row->url,false)?>
	</div>
  </div>
<!--  <div id="cms_masteredit_174_12040" class="formStyle">
    <td colspan="4" align="left" valign="top">
    <img src="/cms/images/cnt_divider.gif" alt="" width="657" height="1" /><br /></td>
  </div>-->
  <div id="cms_masteredit_174_12040" class="formStyle">
    <label>Comment:</label>
    <div class="detail">
		<?=magicclean($row->headline,false)?>
	</div>
  </div>
  <?}?>

<br />
<br />
<br />

<?
if(is_array($orderItems)){
?>

<table cellpadding="15" cellspacing="0" border="0" width="100%" class="tableHead">
	<tr>
        <td width="10%">Image</td>
        <td width="50%">Description</td>
        <td width="10%">Qty</td>
        <td width="10%">Price Ea.</td>
        <td width="10%">Item tot.</td>
 </tr>
</table>
			  
<table cellpadding="15" cellspacing="0" border="0" width="100%" class="tableContent">
	  
<!--TABLE DETAILS BEGINS HERE--> 
	  
<?
	foreach($orderItems as $item){
		
		$product = $cmsDocument->openDocument($item->shortdescription);
		$size = $cmsDocument->openDocument($item->extra3);
		$status = $cmsDocument->openDocument($item->restricted);
		$isGift = ($item->extra5)?' (Gift)':'';
	
		//print_r($product);
		
		if($item->value)
			$priceEach = '$'.number_format($item->value, 2);
		else
			$priceEach = '-';
		if($item->inhouse)
			$priceTotal = '$'.number_format($item->inhouse, 2);
		else
			$priceTotal = '-';			
?> 

      <tr>
        <td width="10%">
<?
	$previewUrl=null;
	$downloadUrl=null;

	if($product->extra11)
		$previewUrl = 	"/html/blob.php?scale=1&width=50&height=50&document=" . $product->documentcode . "&filetypecode=1&fileId=" . $product->extra11;
	else
		$previewUrl = '/images/placeholderInvoice.gif';
//	if($product->organisationalname)
//		$downloadUrl = "/html/blob.php?document=" . $product->documentcode . "&filetypecode=1&fileId=" . $product->{PRODUCT_IMAGE_FIELD};
//	else
		$downloadUrl = '';	
	
?>
			<?if($previewUrl){?><a href="<?= $downloadUrl ?>" target="_blank"><img src="<?= $previewUrl ?>" /></a><?}?>
		</td>
       <td width="50%"><?php echo "<strong>" . $product->title . "</strong><br />"; ?> <?php if(strlen($item->organisationalname) > 0){ echo "<br />" . $item->organisationalname; } ?></td>
        <td width="10%"><?=$item->extra4?></td>
        <td width="10%"><?=$priceEach?></td>
        <td width="10%"><?=$priceTotal?></td>
      </tr>

      

<?
	}

?>
      
  <!--TABLE DETAILS END HERE-->        
    
    </table>
    
<?
}
?>    
    
    
      

        <div class="formStyle">
			<label>Product Subtotal:</label>
			<div class="detail">
				$<?=number_format($row->extra1, 2)?>
			</div>
		</div>
        
	
     
         <div class="formStyle">
			<label>Shipping total:</label>
			<div class="detail">
				$<?php if(is_numeric($row->extra2)) echo number_format($row->extra2, 2); else echo $row->extra2; ?>
			</div>
        </div>
	
     
         <div class="formStyle">
			<label>Order total:</label>
			<div class="detail">
				$<?=number_format($row->extra3, 2)?>
			</div>
        </div>
        
  <div class="clear"></div> 
  
  <a href="/cms/html/index.php?fileNo=1&formid=167&sorts=clear&direction=clear" style="text-decoration:none" class="cms_browsetext"><img src="/cms/html/files/images/icon_folderup.gif" height="20" width="35" border="0"><i>.. Back to <?=($formid==167)?'orders':'order item'?>.</i></a>
  
  
<?
	}
